<template>
  <div class="propertyregist pd30 propertyMaintenance">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>添加物业单位</div>
        <!-- <i class="el-icon-close" @click="handleCloseDialogUpdate"></i> -->
      </div>
      <div class="con">
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>机构名称：</span>
              <el-input v-model="property.name" class="input" placeholder="请输入机构名称" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr">机构简称：</span>
              <el-input v-model="property.nameSimple" class="input" placeholder="请输入机构简称" />
            </div>
          </div>
        </div>
        <!-- <div class="con-row flex flexac pl  none">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr">父机构：</span>
              <el-input class="input"  placeholder="请输入制造商ID"></el-input>
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr">机构级数：</span>
              <el-input class="input" placeholder="请输入制造商名称"></el-input>
            </div>
          </div>
        </div> -->
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">

            <!-- <div class="inputLable inputLable1 flex flexac none">
              <span class="name texttr">排序号：</span>
              <el-input class="input" placeholder="请输入制造商ID"></el-input>
            </div> -->
            <div class="inputLable inputLable1 flex flexac  ">
              <span class="name texttr">使用单位地址：</span>
              <el-input v-model="property.address" class="input" placeholder="请输入使用单位地址" />
            </div>

            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr">邮政编码：</span>
              <el-input v-model="property.zipCode" class="input" placeholder="请输入邮政编码" />
            </div>

          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">

            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">使用单位电话：</span>
              <el-input v-model="property.phone" class="input" type="number" placeholder="请输入使用单位电话" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>安全管理员：</span>
              <el-input v-model="property.securityPerson" class="input" placeholder="请输入安全管理员" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr"><span class="mustval">*</span>安全管理员电话：</span>
              <el-input v-model="property.securityPersonPhone" class="input" type="number" placeholder="请输入安全管理员电话" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr">法人：</span>
              <el-input v-model="property.legalPerson" class="input" placeholder="请输入法人" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">法人电话：</span>
              <el-input v-model="property.legalPersonPhone" class="input" type="number" placeholder="请输入法人电话" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr">法人身份证：</span>
              <el-input v-model="property.legalPersonIdCardNo" class="input" placeholder="请输入法人身份证" />
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <!-- <div class="inputLable inputLable2 flex flexac m-l-60 none">
              <span class="name texttr">物业所属品牌：</span>
              <el-input class="input" placeholder="请输入物业所属品牌"></el-input>
            </div> -->

            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr">组织机构代码：</span>
              <el-input v-model="property.organizationCode" class="input" placeholder="请输入组织机构代码" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr">营业执照代码：</span>
              <el-input v-model="property.businessLicenseCode" class="input" placeholder="请输入营业执照代码" />
            </div>

          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex flexac ">
            <span class="name texttr">行政区域：</span>
            <city :region-code="regionCode" @emitCity="onSendcity" />
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex ">
            <span class="name texttr p-t-10">三证合一证书：</span>
            <uploadImg img-type="sanzheng" @emitImgData="onImgdata" />
          </div>
        </div>
      </div>

      <div class="con-row flex flexac pl ">
        <div class="inputLable wd100 inputLable1 flex ">
          <span class="name texttr">描述：</span>
          <textarea v-model="property.remark" class="markinfo" />
        </div>
      </div>

      <div class="flex  footerBtn m-t-35">
        <el-button class="defaultbtn saveBtn" @click="handleSave">保存</el-button>
        <el-button class="defaultbtn clsoeBtn" @click="handleCloseDialogUpdate">关闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>

import { propertyAdd, propertyUploadimg } from '@/api/maintenance/role'
import { showNotice, successNotice, checkMobile } from '@/utils/toolclass'
import uploadImg from '@/components/uploadImg'
import city from '@/components/city'
export default {
  components: {
    uploadImg, city
  },
  props: {
    addFactory: {
      type: Object
    },
    isEdit: {
      type: Boolean
    }
  },
  data() {
    return {
      picSrc: '',
      // property: {
      //   id: '',
      //   name: '',
      //   nameSimple: '',
      //   zipCode: '',
      //   address: '',
      //   phone: '',
      //   securityPerson: '',
      //   securityPersonPhone: '',

      //   legalPerson: '',
      //   legalPersonPhone: '',
      //   legalPersonIdCardNo: '',
      //   organizationCode: '',
      //   businessLicenseCode: '',
      //   remark: '',
      //     regionCode:{
      //     province: 430000, city: 430100, area: 430102
      // },
      property: {
        id: '',
        name: 'dadaasd',
        nameSimple: 'dadaasd',
        zipCode: '12321',
        address: 'dadaasd',
        phone: '13602703462',
        securityPerson: 'dadaasd',
        securityPersonPhone: '13602703462',
        legalPerson: 'dadaasd',
        legalPersonPhone: '13602703462',
        legalPersonIdCardNo: 'dadaasd',
        organizationCode: 'dadaasd',
        businessLicenseCode: 'dadaasd',
        remark: '',
        regionCode: 430102
      },
      uploadImgparam: {
        id: '',
        businessLicenseFile: '',
        organizationFile: ''
      },

      regionCode: {
        province: 430000, city: 430100, area: 430102
      }

    }
  },
  created() {

  },
  methods: {
    onSendcity(res) {
      console.log('获取城市数据')
      console.log(res)
      this.property.regionCode = res.area
    },
    onImgdata(res) {
      this.uploadImgparam.businessLicenseFile = res.imgfile
      this.uploadImgparam.organizationFile = res.imgfile
    },
    getChange(e) {
      console.log(e)
    },
    handleUpdate() {
      simpleViewUpdate(this.addFactory).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        }
      })
    },
    handleSave() {
      if (this.property.name == '') {
        showNotice('error', '提示', '机构名称为空')
        return
      }
      if (this.property.securityPerson == '') {
        showNotice('error', '提示', '安全管理员为空')
        return
      }
      if (this.property.securityPersonPhone == '') {
        showNotice('error', '提示', '安全管理员电话不能为空')
        return
      }

      if (!checkMobile(this.property.securityPersonPhone)) {
        showNotice('error', '提示', '安全管理员电话手机格式不对')
        return
      }
      if (this.property.legalPersonPhone !== '' && !checkMobile(this.property.legalPersonPhone)) {
        showNotice('error', '提示', '法人电话手机格式不对')
        return
      }
      this.handlePropertyAdd(this.property)
    },
    handleCloseDialog() {
      this.$emit('handleCloseDialog')
    },
    handleCloseDialogUpdate() {
      this.$emit('handleRefresh')
      this.$emit('handleCloseDialog')
    },
    handlePropertyAdd(obj) {
      propertyAdd(obj).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
          this.uploadImgparam.id = res.data.id
          this.handleAddimg(this.uploadImgparam)
        }
      })
    },
    handleAddimg(obj) {
      propertyUploadimg(obj).then((res) => {
      })
    }
  }
}
</script>

<style rel='stylesheet/scss' lang='scss' scoped>
@import "@/styles/addtable.scss";
</style>
